#include "sharemem.hpp"

int main()
{
	int shmid = Getshm();
	// log(Debug,"create shm done,shmid:%d",shmid);

	int fd = open(FILE_PATH, O_WRONLY);
	if (fd < 0)
	{
		// perror("open:");
		log(Fatal, "error string:%s,error code:%d", strerror(errno), errno);
		exit(FIFO_OPEN_ERR);
	}

	// sleep(5);

	char *shmaddr = (char *)shmat(shmid, NULL, 0);
	// qlog(Debug,"attach shm done,addr:0x%x",shmaddr);
	while (1)
	{
		size_t len = 4096;
		cout << "people enter@ ";
		int n = getline(&shmaddr, &len, stdin);
		write(fd, "c", 1);
		shmaddr[n - 1] = '\0';
		//cout << shmaddr << endl;
	}

	shmdt(shmaddr);
	// log(Debug,"detach shm done,addr:0x%x",shmaddr);

	// sleep(3);

	return 0;
}
